<template>
  <view class="collect-exam">
    <view class="exam-list">
      <view class="exam-item" @click="gotoTopic(1, exam.integerZS)">
        <view class="title">正式考试</view>
        <view class="num">{{exam.integerZS}} 道</view>
      </view>

      <view class="exam-item" @click="gotoTopic(2, exam.integerMN)">
        <view class="title">模拟考试</view>
        <view class="num">{{exam.integerMN}} 道</view>
      </view>

      <view class="exam-item" @click="gotoTopic(4, exam.integerMR)">
        <view class="title">每日一题</view>
        <view class="num">{{exam.integerMR}} 道</view>
      </view>

      <view class="exam-item" @click="gotoTopic(5, exam.integerBK)">
        <view class="title">专业提升</view>
        <view class="num">{{exam.integerBK}} 道</view>
      </view>

      <view class="exam-item" @click="gotoTopic(3, exam.integerSW)">
        <view class="title">三违考试</view>
        <view class="num">{{exam.integerSW}} 道</view>
      </view>
    </view>
  </view>
</template>

<script>
import { post_md5 } from './../../common/request'
export default {
  name: 'collectExam',
  data() {
    return {
      exam: {
        integerBK: 0,
        integerMN: 0,
        integerMR: 0,
        integerSW: 0,
        integerZS: 0
      }
    }
  },
  methods: {
    async loadExamList() {
      let params = {
        userId: uni.getStorageSync('userId'),
        type: 3
      }
      let res = await post_md5(
        '/usercenter-app/collect/getcollectbyuserid',
        params
      )
      for (const key in this.exam) {
        if (!this.exam.hasOwnProperty(key)) continue
        if (!res.data.hasOwnProperty(key)) continue
        this.exam[key] = res.data[key]
      }
    },
    gotoTopic(type, num) {
      if (num > 0) {
        uni.navigateTo({
          url: '../collect/collect-topic?examType=' + type
        })
      } else {
        uni.showToast({
          title: '本分类暂无收藏',
          icon: 'none'
        })
      }
    }
  },
  created() {
    this.loadExamList()
  }
}
</script>

<style lang="less">
.collect-exam {
  .exam-list {
    .exam-item {
      display: flex;
      background-color: #fff;
      padding: 40upx 20px 40upx 40upx;
      border-bottom: 1px solid #eee;

      &:last-child {
        border-bottom: none;
      }

      .title {
        flex: auto;
      }

      .num {
        width: 120upx;

        &:after {
          content: ' ';
          position: absolute;
          width: 32upx;
          height: 32upx;
          background-size: contain;
          background-image: url('../../static/icon/icon-go.png');
          background-repeat: no-repeat;
          right: 20upx;
          margin-top: 4upx;
        }
      }
    }
  }
}
</style>